package JAVAcollectionsanddatastructures.Queue;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;


//两个栈实现一个队列：一个站用来出，一个栈用来入
public class QueueTest {
    public Stack<Integer> stack1;
    public Stack<Integer> stack2;

    public QueueTest() {
        this.stack1 = new Stack<>();
        this.stack2 = new Stack<>();
    }

    public void push(int x) {
        stack1.push(x);
    }

    public int pop() {
        if (empty()) {
            return -1;
        }
        if (stack2.isEmpty() == true) {
            while (stack1.isEmpty() == false) {
                int value = stack1.pop();
                stack2.push(value);
            }
        }
        return stack2.pop();
    }

    public int peek() {
        if (empty()) {
            return -1;
        }
        if (stack2.isEmpty() == true) {
            while (stack1.isEmpty() == false) {
                int value = stack1.pop();
                stack2.push(value);
            }
        }
        return stack2.peek();
    }

    public boolean empty() {
        return stack1.empty() && stack2.empty();
    }
}


